package com.yingma.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yingma.system.dao.JcSysOrganizationDao;
import com.yingma.system.entity.JcCarrier;
import com.yingma.system.dao.JcCarrierDao;
import com.yingma.system.service.JcCarrierService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (JcCarrier)表服务实现类
 *
 * @author makejava
 * @since 2020-04-03 19:20:23
 */
@Service("jcCarrierService")
public class JcCarrierServiceImpl implements JcCarrierService {
    @Resource
    private JcCarrierDao jcCarrierDao;

    @Resource
    private JcSysOrganizationDao jcSysOrganizationDao;

    /**
     * 根据条件查询承运商设置信息
     * @param name
     * @param code
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public List<JcCarrier> searchbycondition(String name, String code, Integer pageNum, Integer pageSize) {
        List<JcCarrier> list=null;
        QueryWrapper<JcCarrier> queryWrapper=new QueryWrapper<JcCarrier>();
        if(!name.equals("")&& name!=""){
            queryWrapper.like("NAME",name);
        }
        if(!code.equals("")&& code!=""){
            queryWrapper.like("CODE",code);
        }
        Page<JcCarrier> page=new Page<>(pageNum,pageSize,true);
        IPage<JcCarrier> iPages=jcCarrierDao.selectPage(page,queryWrapper);
        list=iPages.getRecords();
        //组织机构
        for (int i = 0; i <list.size() ; i++) {
            list.get(i).setOrganization(jcSysOrganizationDao.selectById(list.get(i).getJcOrganizationId()));
        }
        //指定组织机构
        for (int i = 0; i <list.size() ; i++) {
            list.get(i).setZdOrganization(jcSysOrganizationDao.selectById(list.get(i).getZdOrganizationId()));
        }
        if(list.size()>0){
            list.get(0).setTotalpageNum(new Long(iPages.getPages()).intValue());
            list.get(0).setTotalSize(new Long(iPages.getTotal()).intValue());
        }
        return list;
    }
}
